package com.chinasofti.manager.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.chinasofti.common.IdWorker;
import com.chinasofti.dao.EmpRepository;
import com.chinasofti.dao.LeaveRepository;
import com.chinasofti.dao.TypeOfLeaveRepository;
import com.chinasofti.manager.service.EmpLeaveService;
import com.chinasofti.model.Emp;
import com.chinasofti.model.MyLeave;
import com.chinasofti.model.TypeOfLeave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Creator: <br>
 * Date: <br>
 * Description: <br>
 */
@Service
@Component
public class EmpLeaveServiceImpl implements EmpLeaveService{
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private EmpRepository empRepository;
    @Autowired
    private LeaveRepository leaveRepository;
    @Autowired
    private TypeOfLeaveRepository typeOfLeaveRepository;

    @Override
    public void leave(String name, String type,
                      String reason,
                      String start, String end) {
        MyLeave leave = new MyLeave();
        leave.setId(idWorker.nextId());
        Emp emp = empRepository.findByName(name);
        leave.setName(emp.getName());
        leave.setDeptName(emp.getDeptName());

        leave.setType(type);
        leave.setReason(reason);
        leave.setStart(start);
        leave.setEnd(end);
        leave.setState(2);
        leaveRepository.save(leave);
    }

    @Override
    public List<TypeOfLeave> queryTypeList() {
        List<TypeOfLeave> typeOfLeaves = typeOfLeaveRepository.findAll();
        return typeOfLeaves;
    }

}
